package cn.iocoder.yudao.module.member.growth.controller.app;

import cn.iocoder.yudao.framework.business.basic.annotation.AppJsonView;
import cn.iocoder.yudao.framework.business.basic.controller.PageController;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.growth.pojo.dto.GrowthRecordQueryDTO;
import cn.iocoder.yudao.module.member.growth.pojo.po.GrowthRecord;
import cn.iocoder.yudao.module.member.growth.pojo.vo.GrowthRecordVO;
import cn.iocoder.yudao.module.member.growth.service.app.AppGrowthRecordService;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * 前端控制器
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/05/08
 */
@Tag(name = "用户 APP - 贡献值记录")
@RestController
@RequestMapping("/member/growth/record")
public class AppGrowthRecordController implements PageController<GrowthRecordVO, GrowthRecordQueryDTO> {
    @Resource
    private AppGrowthRecordService appGrowthRecordService;

    @JsonView(AppJsonView.class)
    @Override
    public CommonResult<PageResult<GrowthRecordVO>> getPage(Integer pageNo, Integer pageSize, GrowthRecordQueryDTO param) {
        Long userId = getLoginUserId();
        CoreQueryWrapper<GrowthRecord> wrapper = new CoreQueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.likeIfPresent("title", param.getTitle());
        wrapper.orderByDesc("id");
        return CommonResult.success(appGrowthRecordService.getPage(pageNo, pageSize, wrapper));
    }

}
